﻿using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using DryIoc;
using HandyControl.Controls;
using HandyControl.Data;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using YJTTool.Common.Helper;
using YJTTool.DBBaseServer.AbstractModel;
using YJTTool.DBBaseServer.Entities;
using YJTTool.Handy.Model;

namespace YJTTool.Handy.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        #region 内部字段

        private readonly IRegionManager _regionManager;

        private readonly AbstractUserConfigServer abstractUserConfig;
        #endregion

        #region 集合
        public ObservableCollection<SideMenuItem> MenuItems { get; private set; } = new ObservableCollection<SideMenuItem>();
        #endregion

        #region 属性
        private UserConfigDto userConfig;

        public UserConfigDto UserConfig
        {
            get => userConfig;
            set
            {
                userConfig = value;
                RaisePropertyChanged();
            }
        }

        private string _title = "YJT Tools";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }
        #endregion


        public DelegateCommand<FunctionEventArgs<object>> SwitchItemCmd => new(SwitchItem);

        private void SwitchItem(FunctionEventArgs<object> info) => Growl.Info((info.Info as SideMenuItem)?.Header .ToString());

        public DelegateCommand<string> SelectCmd { get; set; }

        
        public MainWindowViewModel(IRegionManager regionManager, AbstractUserConfigServer abstractUserConfig)
        {
            _regionManager = regionManager;
            this.abstractUserConfig = abstractUserConfig;
            SelectCmd = new DelegateCommand<string>(s => 
            {
                Select(s);
            });

            InitConfig();
            TimerHelper.Instance.Init() ;
        }
        /// <summary>
        /// 初始化配置
        /// </summary>
        private void InitConfig()
        {
            SelectCmd.Execute(null);
        }
        /// <summary>
        /// 选中功能
        /// </summary>
        /// <param name="header"></param>
        private void Select(string header)
        {
            switch (header)
            {
                case "药品对照":
                    _regionManager.RequestNavigate("ContentRegion", "DrugControlsView");
                    break;
                case "远程信息":
                    _regionManager.RequestNavigate("ContentRegion", "CustomerInfoView");
                    break;
                case "定时提示":
                    _regionManager.RequestNavigate("ContentRegion", "ScheduledRemindersView");
                    break;
                case "Json转换":
                    _regionManager.RequestNavigate("ContentRegion", "JsonConversionView");
                    break;
                default:
                    _regionManager.RequestNavigate("ContentRegion", "HomePage");
                    break;
            }
        }
    }
}
